home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 2000
/
MacHack 2000.toast
/
pc
/
The Hacks
/
Softshoe
/
Lisa's Mac Parts
/
Windows
/
WindowObject.cp
< prev
next >
Wrap
Text File
|
2000-06-23
|
4KB
|
218 lines
// WindowObject.cp
#ifndef WindowObject_h
#include "WindowObject.h"
#endif
#ifndef MemoryFullError_h
#include "MemoryFullError.h"
#endif
#ifndef GraphicsDeviceObject_h
#include "GraphicsDeviceObject.h"
#endif
#ifndef SplitIntegers_h
#include "SplitIntegers.h"
#endif
#ifndef RegionObject_h
#include "RegionObject.h"
#endif
// This is a cheap compile-time assertion that
// the sizes are equal:
static const void *shouldBeNull
= sizeof(WindowRecord) - sizeof(WindowObject);
WindowObject::WindowObject( Definition definition,
bool withClosebox )
{
static Rect defaultBounds = { 30, 30, 130, 130 };
GrafPort *result = NewCWindow( reinterpret_cast<Ptr>( &port ),
&defaultBounds,
"\p",
false,
definition,
0,
withClosebox,
0 );
if ( result == 0 )
throw MemoryFullError();
Assert( result == &port );
SetPort( result );
}
PointObject WindowObject::SizeByDragging( PointObject mouse,
PointObject minimum,
PointObject maximum )
{
// GrowWindow doesn't let you acheive the maximum:
if ( maximum.h < maxint16 )
maximum.h++;
if ( maximum.v < maxint16 )
maximum.v++;
Rectangle bounds( minimum.h,
minimum.v,
maximum.h,
maximum.v );
uint32 result = GrowWindow( &port, mouse, &bounds );
if ( result == 0 )
return Size();
return PointObject( Word0( result ), Word1( result ) );
}
void WindowObject::SetBounds( Rectangle newBounds )
{
Rectangle oldBounds( GlobalBounds() );
if ( newBounds == oldBounds )
return;
if ( newBounds.TopLeft() != oldBounds.TopLeft() )
SetPosition( newBounds.TopLeft() );
if ( newBounds.Size() != oldBounds.Size() )
SetSize( newBounds.Size() );
}
void WindowObject::ZoomToUserBounds()
{
ZoomWindow( &port, inZoomIn, false );
InvalRect( &port.portRect );
}
void WindowObject::ZoomToStandardBounds()
{
ZoomWindow( &port, inZoomOut, false );
InvalRect( &port.portRect );
}
WStateData& WindowObject::StateData()
{
Assert( dataHandle != 0 );
Assert( *dataHandle != 0 );
return **reinterpret_cast<WStateData **>( dataHandle );
}
const WStateData& WindowObject::StateData() const
{
Assert( dataHandle != 0 );
Assert( *dataHandle != 0 );
return **reinterpret_cast<WStateData **>( dataHandle );
}
uint32 WindowObject::Index() const
{
Assert( Visible() );
if ( !Visible() )
throw OSError( errAENoSuchObject );
uint32 index = 1;
for ( WindowObject *w = Front(); w != 0; w = w->Next() )
{
if ( !w->Visible() )
continue;
if ( w == this )
return index;
index++;
}
Assert( 0 );
throw OSError( errAENoSuchObject );
return 0;
}
void WindowObject::SetIndex( uint32 newIndex )
{
Assert( newIndex > 0 );
if ( newIndex == 0 )
throw OSError( errAEIllegalIndex );
if ( newIndex == 1 )
Select();
else
{
WindowObject *w = Front();
while ( w != 0 && newIndex > 2 )
{
if ( w->Visible() )
newIndex--;
w = w->Next();
}
if ( w == 0 )
throw OSError( errAEIllegalIndex );
SendBehind( *w );
}
if ( !Visible() )
Show();
}
GDHandle WindowObject::NearestScreen() const
{
return GraphicsDeviceObject::Nearest( GlobalBounds() );
}
GDHandle WindowObject::DeepestScreen() const
{
return GraphicsDeviceObject::Deepest( GlobalBounds() );
}
uint32 WindowObject::CountVisibleWindows()
{
uint32 count = 0;
for ( WindowObject *w = Front(); w != 0; w = w->Next() )
if ( w->Visible() )
count++;
return count;
}
uint32 WindowObject::CountVisibleWindows( Rectangle target )
{
uint32 count = 0;
for ( WindowObject *w = Front(); w != 0; w = w->Next() )
if ( w->Visible() && target.Contains( w->GlobalBounds().TopLeft() ) )
count++;
return count;
}
Rectangle WindowObject::FrameSize() const
{
static RegionObject structure;
GetWindowRegion( const_cast<GrafPtr>( &port ),
kWindowStructureRgn,
structure );
Rectangle bounds( GlobalBounds() );
Assert( bounds <= structure.Bounds() );
return Rectangle( structure.Bounds().left - bounds.left,
structure.Bounds().top - bounds.top,
structure.Bounds().right - bounds.right,
structure.Bounds().bottom - bounds.bottom );
}
WindowObject *WindowObject::DoCheckedCast( const void *p )
{
for ( WindowObject *w = Front(); w != 0; w = w->Next() )
if ( w == p )
return w;
return 0;
}